<template>
  <UploadContainer @uploadImg="sendImgMessage">
    <div class="chatContent">
      <Resizeable :driver="2" flex="column">
        <template #left>
          <ChatRecordList />
        </template>
        <template #right>
          <EditAreaContent /> 
        </template>
      </Resizeable>
      <div class="rightContentExtra" :class="computedCustomClass" v-if="showExtraInfo">
        <div @click="switchHandler">
          <div class="userListWrapper">
            <div class="userWrapper">
              <div class="userA">
                <img src="@/assets/images/tx.jpg"/>
              </div>
              <span>Baby</span>
            </div>
            <div class="addWrapepr">
              <div class="userA">
                <PlusOutlined />
              </div>
              <span>添加</span>
            </div>
          </div>
          <div class="chatRecords">
            <span>聊天记录</span>
            <RightOutlined :style="{color: '#ccc'}"/>
          </div>
          <div class="operateWrapper">
            <div class="operate">
              <span>消息免打扰</span>
              <Switch v-model:value="noDisturb" size='small' @click="switchHandler"/>
            </div>
            <div class="operate">
              <span>置顶聊天</span>
              <Switch v-model:value="topping" size='small' @click="switchHandler"/>
            </div>
          </div>
          <div class="otherWrapper">
            <span>清空聊天记录</span>
          </div>
        </div>
      </div>
    </div>
  </UploadContainer>
</template>
<script lang="ts" setup>
// 工具
import { ref, computed, onMounted, onUnmounted } from 'vue'
import useChatStore from '@/stores/chatStore'
// 组件
import { Switch } from 'ant-design-vue'
import PubSub from 'pubsub-js'
import ChatRecordList from '@/components/ChatRecordList.vue'
import EditAreaContent from '@/components/EditAreaContent.vue'
import UploadContainer from '@/components/custom/UploadContainer/index.vue'
import Resizeable from '@/components/custom/Resizeable/index.vue'
import { PlusOutlined, RightOutlined } from '@ant-design/icons-vue'
// 属性
const showExtraInfo = ref<Boolean>(false)
const extraClass = ref<Array<string>>([])
const computedCustomClass = computed(()=> extraClass.value.join(' '))
const noDisturb = ref<Boolean>(false) // 消息免打扰
const topping = ref<Boolean>(false) // 消息置顶
const chatStore = useChatStore()
const switchHandler = (e: any) => {
  e.stopPropagation()
}
// 发送图片消息
const sendImgMessage = (files: any) => {
  files.forEach((file: any) => {
    chatStore.sendMessage(1, '', file, '', '')  // 调用发送消息接口
  });
}
onMounted(()=> {
  // 订阅弹窗消息
  PubSub.subscribe('showExtraInfo', (msg: string, data: any) => {
     if(data.hide) {
       if(!showExtraInfo.value) return
       extraClass.value.splice(extraClass.value.findIndex(item=> item==='rightSliderIn'), 1)
        extraClass.value.push('rightSliderOut')
        return setTimeout(()=> {
          showExtraInfo.value = false
        }, 300)
     } else {
      if(showExtraInfo.value) { // 隐藏
        extraClass.value.splice(extraClass.value.findIndex(item=> item==='rightSliderIn'), 1)
        extraClass.value.push('rightSliderOut')
        return setTimeout(()=> {
          showExtraInfo.value = false
        }, 300)
      } else { // 显示
        extraClass.value.splice(extraClass.value.findIndex(item=> item==='rightSliderOut'), 1)
        extraClass.value.push('rightSliderIn')
        showExtraInfo.value = !showExtraInfo.value
      }
     }
  })
})
</script>
<style lang="less" scoped>
.chatContent {
  flex: 1;
  position: relative;
}
.chatWrapper {
  height: 100%;
  flex: 1;
  width: 100%;
}
.rightContentExtra {
  width: 294.72px;
  overflow: hidden;
  z-index: -1;
  padding: 20px;
  box-sizing: border-box;
  border-left: 0.5px solid #e0e0e0;
  width: 294.72px;
  background-color: #ffffff;
  overflow: hidden;
  z-index: 35;
  padding: 25px;
  box-sizing: border-box;
  position: absolute;
  right: 0;
  height: 100%;
  top: 0;
  border-left: 0.5px solid #e0e0e0;
  .userListWrapper {
    display: flex;
    gap: 20px;
    border-bottom: 1px solid #efefef;
    padding-bottom: 20px;
    .userWrapper, .addWrapepr {
      gap: 5px;
      display: flex;
      flex-direction: column;
      align-items: center;
      .userA {
        background-color: white;
        border: 1px solid #ccc;
        width: 35px;
        height: 35px;
        overflow: hidden;
        display: flex;
        align-items: center;  
        justify-content: center;
        img {
          width: 35px;
        }
      }
      span {
        color: #2c2c2c;
        font-size: 13px;
      }
    }
  }
  .chatRecords {
    padding: 15px 0px;
    border-bottom: 1px solid #efefef;
    font-size: 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .operateWrapper {
    padding: 20px 0;
    gap: 20px;
    display: flex;
    flex-direction: column;
    font-size: 14px;
    border-bottom: 1px solid #efefef;
    .operate {
      display: flex;
      justify-content: space-between;
      button {
        outline: none;
      }

    }
  }
  .otherWrapper {
    padding: 20px 0;
    color: red;
    text-align: center;
    font-size: 14px;
  }
}
.rightSliderIn {
  animation: 0.3s ease-out 0s 1 slideOutFromRight;
}
.rightSliderOut {
  animation: 0.3s ease-out 0s 1 slideInFromLeft;
}
@keyframes slideInFromLeft {
  0% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(100%);
  }
}
@keyframes slideOutFromRight {
  0% {
    transform: translateX(100%);
  }
  100% {
    transform: translateX(0);
  }
}
</style>
